package com.Akronmcp.hta.main;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarFlag;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;

import com.Akronmcp.hta.obj.HCondition;
import com.Akronmcp.hta.obj.HManager;
import com.Akronmcp.hta.obj.HPar;
import com.Akronmcp.hta.obj.HPar2;
import com.Akronmcp.hta.obj.HopBar;
import com.Akronmcp.hta.obj.HopBook;
import com.Akronmcp.hta.obj.HopChat;
import com.Akronmcp.hta.obj.HopHolo;
import com.Akronmcp.hta.obj.HopTitle;
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
import com.google.gson.JsonArray;

import me.clip.placeholderapi.PlaceholderAPI;

public class HLoader {

	static File df = HM.df;
	static FileConfiguration conf = HM.conf;
	static FileConfiguration lang = HM.lang;

	/**重载,基本载入配置*/
	 static void reload_conf(HManager hta) throws Exception//重载
    {
    		
         conf = null;
         lang = null;
         //清空
         
         conf = YamlConfiguration.loadConfiguration(new File(df,"config.yml"));
        
         String langtype = conf.getString("langtype");
    	 lang = YamlConfiguration.loadConfiguration(new File(df+"//lang",langtype+".yml"));
        //载入
         HM.lang = lang;
    	//.getConfigurationSection
    	//获取子节点
    	//.getkeys(false)
    	//获取子节点集合
         if(HM.papiloaded)
         if(HM.hololoaded)
         {
        	 //holo声明papi变量
        	 List<String> l = conf.getStringList("holopapis");
        	 l.forEach((o)->
        	 {
        		 
        		 new ArrayList<RelativePlaceholder>(RelativePlaceholder.getRegistry())
        		 .forEach(new Consumer<RelativePlaceholder>() {
					@Override
					public void accept(RelativePlaceholder t) {
						if(t.getTextPlaceholder().equals(o))
						RelativePlaceholder.getRegistry().remove(t);
					}
				});
        		 
        		 
        		 RelativePlaceholder.register(new RelativePlaceholder(o) {
    				@Override
    				public String getReplacement(Player p) {
    					return PlaceholderAPI.setPlaceholders(p,o);
    				}
    			 });
        	 });
        	 
        	 HM.getPlugin(HolographicDisplays.class).hookProtocolLib();
        	 System.out.println("成功载入悬浮变量");
         }
         
         String in = conf.getString("input");
         if(in!=null)
         {
        	 hta.clearAll();
        	 String ins[] = in.split("\\n");
        	 
        	 for(String file:ins)
        	 {
        		try 
        		{
        			 load(hta,new File(df,file.trim()));
        		}catch (Exception e) {
        			 e.printStackTrace();
        			 System.out.println(lang.getString("loadnotok"));
				}
        	 }
        	 hta.initAllHopChat();
        	 hta.initAllHopBook();
        	 hta.initAllHopHolo();
         }//清空,遍历载入文件
         
    }
    
	/**载入hchat*/
    static void load_htx(HManager hta,YamlConfiguration htf)
    {
    	
    	ConfigurationSection parhtx = htf.getConfigurationSection("HopChats");
    	HopChat dhtx = null; 
        boolean isdhtx = false;
        //是否已载入default
    	if(parhtx!=null)
    	for(String thtid:parhtx.getKeys(false))
    	{//迭代子节点,创建HopTexts
    		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
    		HopChat ht;
    	    
    		if(thtid.equals("default"))
    	    {
    	    	ht = new HopChat(hta);
    	    	dhtx = ht;
    	    	isdhtx = true;
    	    }else if(isdhtx)
    	    {//克隆default
    	    	
    	        ht = (HopChat) dhtx.clone();
    	        ht.ja = new JsonArray();
    	    }else
    	    {
    	    	ht = new HopChat(hta);
    	    }
    		
    		String path = "HopChats." + thtid + ".";
    		//子节点路径
    		
    		boolean papi = htf.getBoolean(path + "papi");
    		
    		String cea = htf.getString(path + "clickEvent.action");//.toLowerCase();
    		String cev = htf.getString(path + "clickEvent.value");//.toLowerCase();
    		
    		String hea = htf.getString(path + "hoverEvent.action");//.toLowerCase();
    		String hev = htf.getString(path + "hoverEvent.value");
    		String tx =  htf.getString(path + "text");
    		
    		String pre = htf.getString(path + "prefix");
    		String suf = htf.getString(path + "suffix");
    		
    			
    		if((cea!=null)&&(cev!=null))
    	     ht.setClickEvent(cea,cev.replace("&", "§"));
    		
    		if((hea!=null)&&(hev!=null))
        	 ht.setHoverEvent(hea,hev.replace("&", "§"));
    		
    		if(pre!=null)
    		ht.setPrefix(pre.replace("&", "§"));
    		
    		if(suf!=null)
    		ht.setSuffix(suf.replace("&", "§"));
    		
    		//判断其他设置
    		
    		if(papi)
    		ht.setPapi(papi);
    		
    	    if(tx!=null)
    	    {//判断text
    	    	ht.setText(tx.trim().replace("&", "§"));
    	    }
	    	
    		if(!thtid.equals("default"))
	    	ht.addToList(thtid);
    	}
    	
    }
    /**载入htitle*/
    static void load_htl(HManager hta,YamlConfiguration htf)
    {
    	
    	ConfigurationSection parhtl = htf.getConfigurationSection("HopTitles");
    	
	    HopTitle dhtl = null; 
	    //预定义默认对象
	    
        boolean isdhtl = false;
        //是否已载入default
	
    	if(parhtl!=null)
    	for(String thtid:parhtl.getKeys(false))
    	{//迭代子节点,创建HopTexts
    		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
    	    
    		HopTitle ht;
    	    
    		if(thtid.equals("default"))
    	    {//判断是否为默认节点
    	    	ht = new HopTitle(hta);
    	    	dhtl = ht;
    	        //储存默认节点
    	    	isdhtl = true;
    	    	
    	    }else if(isdhtl)
    	    {//克隆default的配置
    	    	
    	        ht = (HopTitle) dhtl.clone();
    	        
    	    }else
    	    {
    	    	ht = new HopTitle(hta);
    	    }
    	    	
    		
    		String path = "HopTitles." + thtid + ".";
    		//子节点路径
    		
    		boolean papi = htf.getBoolean(path + "papi");
    		boolean endbyhop = htf.getBoolean(path + "endbyhop");
    		
    	    String cycle = htf.getString(path + "cycle");
    		String fadein = htf.getString(path + "fadein");
    		String fadeout =  htf.getString(path + "fadeout");
    		String staytime = htf.getString(path + "staytime");
    		String ticktime = htf.getString(path + "ticktime");

    		String pri = htf.getString(path + "pri");
    		
    		String type = htf.getString(path + "type");
    		String text = htf.getString(path + "text");
    		String sub = htf.getString(path + "subtext");
    		
    		String hop = htf.getString(path + "hop");
    		String module = htf.getString(path + "module");
    		
    		
    		//读入
    		
    		if(papi)
    	    ht.setPapi(papi);
    		
    		if(endbyhop)
        	ht.setEndByHop(endbyhop);
    		
    		if(cycle!=null)
    		ht.setCycle(Integer.valueOf(cycle));
    		
    		if(fadein!=null)
        	ht.setFadein(Integer.valueOf(fadein));
    		
    		if(fadeout!=null)
        	ht.setFadeout(Integer.valueOf(fadeout));
    		
    		if(staytime!=null)
        	ht.setStayTime(Integer.valueOf(staytime));
    		
    		if(ticktime!=null)
            ht.setTickTime(Integer.valueOf(ticktime));
         		
    		
    		if(pri!=null)
    		ht.setPriority(Integer.valueOf(pri));	
    		
    		if(type!=null)
    		ht.setType(type);
    		
    		if(sub!=null)
    		if(sub.startsWith("hchat:"))
    		{
    			ht.setSubText(sub);
    		}else if(sub.startsWith("htitle:"))
    		{
    			ht.setSubText(sub);
    		}else if(sub.startsWith("hbar:"))
    		{
    			ht.setSubText(sub);
    		}else
    		{
    			if(ht.getType().equals("TITLE"))
    			{	
	    			HopTitle sht = new HopTitle(hta);
	    			sht.setText(sub);
	    			sht.setType("subtitle");	
	    			if(!ht.gethoptypes().isEmpty())
	    			sht.setFadein(0);
	    			
	    			ht.setSubText(sht);
    			}
    		}
    		
    		if(text!=null)
    		ht.setText(text.replace("&", "§"));
    		
    		if(hop!=null)
    		{
    		    ht.setHoptypes(new ArrayList<String>());
    			ht.setHopargs(new ArrayList<String[]>());
    			ht.setFrameList(new ArrayList<String>());
    			//重新定义
    			
    			String rows[] = hop.trim().replace("&", "§").split("\\n");
    			if(rows.length>0)
    			for(String row:rows)
    			if(!row.equals(""))
    			{
    				row = row.trim();
    				int b = row.indexOf("(");
    				int e = row.indexOf(")");

    				if(b==-1||e==-1)
    				continue;
    				
    				String ty = row.substring(0, b).toUpperCase();
    				String args[] = row.substring(b+1, e).split(",");
    				
    				ht.addTextHop(ty, args);
    				
    			}
    			
    		}else if(text!=null)
    		{//重定义效果里的"默认文本",重造
    			if(!ht.gethoptypes().isEmpty())
    			{
    				List<String> thtl = new ArrayList<String>(ht.gethoptypes());
        			List<String[]> thtal = new ArrayList<String[]>(ht.getHopargs());
        			ht.setHoptypes(new ArrayList<String>());
         			ht.setHopargs(new ArrayList<String[]>());
        			ht.setFrameList(new ArrayList<String>());
    				
        			int in = 0;
        			for(String ty:thtl)
        			{
        				
        				ht.addTextHop(ty,thtal.get(in));
        				in++;
        			}
        			
    			}
    			
    		}
    		
    		if(module!=null)
    		{
    			ht.setModule(module);
    		}
    		
    		if(!thtid.equals("default"))
    		ht.addToList(thtid);
    		
    	}
    	
    	
    }
    
    static void load_hth(HManager hta,YamlConfiguration htf)
    {
    	
    	ConfigurationSection parhtl = htf.getConfigurationSection("HopHolos");
    	
    	HopHolo dhtl = null; 
	    //预定义默认对象
	    
        boolean isdhtl = false;
        //是否已载入default
	
    	if(parhtl!=null)
    	for(String thtid:parhtl.getKeys(false))
    	{//迭代子节点,创建HopTexts
    		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
    	    
    		HopHolo ht;
    	    
    		if(thtid.equals("default"))
    	    {//判断是否为默认节点
    	    	ht = new HopHolo(hta);
    	    	dhtl = ht;
    	        //储存默认节点
    	    	isdhtl = true;
    	    	
    	    }else if(isdhtl)
    	    {//克隆default的配置
    	    	
    	        ht = (HopHolo) dhtl.clone();
    	        
    	    }else
    	    {
    	    	ht = new HopHolo(hta);
    	    }
    	    	
    		
    		String path = "HopHolos." + thtid + ".";
    		//子节点路径
    		
    		String ticktime = htf.getString(path + "ticktime");

    		String text = htf.getString(path + "text");
    		
    		String fps = htf.getString(path + "fps");
    		
    		String prefix = htf.getString(path + "prefix");
    		String suffix = htf.getString(path + "suffix");
    		
    		String hop = htf.getString(path + "hop");
    		String module = htf.getString(path + "module");
    		String local = htf.getString(path + "location");
    		
    		
    		String cmd = htf.getString(path+"cmd");
    		
    		//读入

    		if(prefix!=null)
    			ht.setPreList(getList(prefix));
    		if(suffix!=null)
    			ht.setSufList(getList(suffix));
    		
    		if(fps!=null)
    		{
    			List<List<String>> tfps = new ArrayList<>();
    			String[] a = fps.trim().replace("&", "§").split("\\n//\\n");
    	    	for(int i=0;i<a.length;i++)
    	    	{
    	    		tfps.add(getList(a[i]));
    	    	}
    	    	ht.setFps(tfps);
    		}
    		
    		if(local!=null)
    		{
				String a[] = local.split(",");
				if(a.length==4)
				{
					World w = Bukkit.getWorld(a[0]);
					double x = Double.valueOf(a[1]);
					double y = Double.valueOf(a[2]);
					double z = Double.valueOf(a[3]);
					Location lo = new Location(w,x,y,z);
					ht.setLocation(lo);
				}
    		}
    		
    		if(ticktime!=null)
            ht.setTickTime(Integer.valueOf(ticktime));
    		
    		if(text!=null)
    		ht.setText(text.replace("&", "§"));
    		
    		if(cmd!=null)
    		ht.setTouchCmd(cmd);
    		
    		if(hop!=null)
    		{
    		    ht.setHoptypes(new ArrayList<String>());
    			ht.setHopargs(new ArrayList<String[]>());
    			ht.setFrameList(new ArrayList<String>());
    			//重新定义
    			
    			String rows[] = hop.trim().replace("&", "§").split("\\n");
    			if(rows.length>0)
    			for(String row:rows)
    			if(!row.equals(""))
    			{
    				row = row.trim();
    				int b = row.indexOf("(");
    				int e = row.indexOf(")");

    				if(b==-1||e==-1)
    				continue;
    				
    				String ty = row.substring(0, b).toUpperCase();
    				String args[] = row.substring(b+1, e).split(",");
    				
    				ht.addTextHop(ty, args);
    				
    			}
    			
    		}else if(text!=null)
    		{//重定义效果里的"默认文本",重造
    			if(!ht.gethoptypes().isEmpty())
    			{
    				List<String> thtl = new ArrayList<String>(ht.gethoptypes());
        			List<String[]> thtal = new ArrayList<String[]>(ht.getHopargs());
        			ht.setHoptypes(new ArrayList<String>());
         			ht.setHopargs(new ArrayList<String[]>());
        			ht.setFrameList(new ArrayList<String>());
    				
        			int in = 0;
        			for(String ty:thtl)
        			{
        				ht.addTextHop(ty,thtal.get(in));
        				in++;
        			}
    			}
    			
    		}
    		
    		if(module!=null)
    		{
    			ht.setModule(module);
    		}
    		
    		if(!thtid.equals("default"))
    		ht.addToList(thtid);
    		
    	}
    	
    	
    }

    static void load_htb(HManager hta,YamlConfiguration htf)
    {
    	ConfigurationSection parhtb = htf.getConfigurationSection("HopBars");
        HopBar dhb = null; 
        boolean isdhb = false;
        //是否已载入default
        
     	if(parhtb!=null)
     	for(String thtid:parhtb.getKeys(false))
     	{//迭代子节点,创建HopTexts
     		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
     	    HopBar ht;
     	    
     		if(thtid.equals("default"))
     	    {
     	    	ht = new HopBar(hta);
     	    	dhb = ht;
     	    	isdhb = true;
     	    }else if(isdhb)
     	    {//克隆default
     	        ht = (HopBar) dhb.clone();
     	        try {
     	        	
     	        	ht.bar = Bukkit.createBossBar("",
     	        			dhb.bar.getColor(),
     	        			dhb.bar.getStyle());	
     	        }catch (Exception e) {
				}
     	        
     	    }else
     	    {
     	    	ht = new HopBar(hta);
     	    }
     	    	
     		String path = "HopBars." + thtid + ".";
     		//子节点路径
     		 
     		
     		boolean papi = htf.getBoolean(path + "papi");
     		boolean endbyhop = htf.getBoolean(path + "endbyhop");
     		
     	    String cycle = htf.getString(path + "cycle");
     		String staytime = htf.getString(path + "staytime");
     		String ticktime = htf.getString(path + "ticktime");
     		
     		String type = htf.getString(path + "type");
     		
     		String barhop = htf.getString(path + "barhop");
     		
     		String text = htf.getString(path + "text");
     		String sub = htf.getString(path + "subtext");
     		
     		String hop = htf.getString(path + "hop");
    		String module = htf.getString(path + "module");

     		//读入
    		
     		
     		if(papi)
     	    ht.setPapi(papi);
     		
     		if(endbyhop)
         	ht.setEndByHop(endbyhop);
     		
     		if(cycle!=null)
     		ht.setCycle(Integer.valueOf(cycle));
     		
     		if(staytime!=null)
         	ht.setStayTime(Integer.valueOf(staytime));

     		if(ticktime!=null)
         	ht.setTickTime(Integer.valueOf(ticktime));
     		
     	
     		if(type!=null)
     		{
     			String args[] = type.split(",");
     		
     			try {
     				BossBar bar = ht.getBar();
     				
     				if(args.length>0)
     					bar.setColor(BarColor.valueOf(args[0]));
     				
     				if(args.length>1)
     					bar.setStyle(BarStyle.valueOf(args[1]));
     				
     				if(args.length>2)
     					bar.addFlag(BarFlag.valueOf(args[2]));
     			}catch (Exception e) {
				}
     		
     		}
     		
     		if(barhop!=null)
     		ht.setBarHop(barhop);
     			
     		if(sub!=null)
        		if(sub.startsWith("hchat:"))
        		{
        			ht.setSubText(sub);
        		}else if(sub.startsWith("htitle:"))
        		{
        			ht.setSubText(sub);
        		}else if(sub.startsWith("hbar:"))
        		{
        			ht.setSubText(sub);
        		}
     	
     		if(text!=null)
        		ht.setText(text.replace("&", "§"));
        		
    		if(hop!=null)
    		{
     			
     			ht.setHoptypes(new ArrayList<String>());
     			ht.setHopargs(new ArrayList<String[]>());
     			ht.setFrameList(new ArrayList<String>());
     			//重新定义
     			String rows[] = hop.trim().replace("&", "§").split("\\n");
     			if(rows.length>0)
     			for(String row:rows)
     			if(!row.equals(""))
     			{
     				row = row.trim();
     				int b = row.indexOf("(");
     				int e = row.indexOf(")");

     				if(b==-1||e==-1)
     				continue;
     				
     				String ty = row.substring(0, b).toUpperCase();
     				String args[] = row.substring(b+1, e).split(",");
     				
     				ht.addTextHop(ty, args);
     				
     				
     			}
     			
     		}else if(text!=null)
    		{//重定义效果里的"默认文本",重造
    			if(!ht.gethoptypes().isEmpty())
    			{
    				List<String> thtl = new ArrayList<String>(ht.gethoptypes());
        			List<String[]> thtal = new ArrayList<String[]>(ht.getHopargs());
        			ht.setHoptypes(new ArrayList<String>());
         			ht.setHopargs(new ArrayList<String[]>());	
        			ht.setFrameList(new ArrayList<String>());
    				
        			int in = 0;
        			for(String ty:thtl)
        			{
        				ht.addTextHop(ty,thtal.get(in));
        				in++;
        			}
    			}
    		}
     		
    		if(module!=null)
    		{
    			ht.setModule(module);
    		}
    		
    		if(!thtid.equals("default"))
     		ht.addToList(thtid);
     		
     	}
     	
    }

    static void load_hto(HManager hta,YamlConfiguration htf)
    {
    	ConfigurationSection parhto = htf.getConfigurationSection("HopBooks");
        
    	if(parhto!=null)
    	for(String thtid:parhto.getKeys(false))
    	{//迭代子节点,创建HopTexts
    		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
    	    
    		String path = "HopBooks." + thtid + ".";
    		//子节点路径
    		HopBook ht = new HopBook(hta);
    		
    		boolean papi = htf.getBoolean(path + "papi");
    		boolean issep = htf.getBoolean(path + "issep");
    		
    		String prehtx = htf.getString(path + "prehchat");
    		String sufhtx = htf.getString(path + "sufhchat");
    		
    		String extra = htf.getString(path + "extra");
    		
    		String title = htf.getString(path + "title","1");//.toLowerCase();
    		String author = htf.getString(path + "author","1");//.toLowerCase();
    		
    		String lores = htf.getString(path + "lores");//.toLowerCase();
    		String pages = htf.getString(path + "pages");
    		//读入
    		
    		
    		
    		ItemStack bo = ht.getItemBook();
    		BookMeta bom = (BookMeta) bo.getItemMeta();
    		
    		
    		if(papi)
        	ht.setPapi(papi);
    		
    		if(issep)
            ht.setSep(issep);
    	
    		if(prehtx!=null)
    		ht.setPrehtx(hta.getHopChat(prehtx));
    		
    		if(sufhtx!=null)
    		ht.setSufhtx(hta.getHopChat(sufhtx));
    		    		
    		if(title!=null)
    		bom.setTitle(title.replace("&", "§"));
    		
    		if(author!=null)
    		bom.setAuthor(author.replace("&", "§"));
    		
    		if(lores!=null)
    		{
    		   String[] lorel = lores.replace("&", "§").split("\\n");
    		   bom.setLore(Arrays.asList(lorel));
    		   
    		}
    		
    		if(pages!=null)
    		{
    		   String[] pal = pages.trim().split("\\n");
    		   
    		   for(String pa:pal)
    		   ht.addHPage(hta.getHopChat(pa.trim()));
    		   
    		}
    		if(extra!=null)
    		ht.setExtra(extra.replace("&", "§"));
    		
    		bo.setItemMeta(bom);
    		ht.setId(thtid);
    		
    		if(!thtid.equals("default"))
    		ht.addToList(thtid);
    		
    	}
    	
    }
    
    static void load_htm(HManager hta,YamlConfiguration htf)
    {
    	ConfigurationSection parhtm = htf.getConfigurationSection("HopModules");
        HPar dhb = null; 
        boolean isdhb = false;
        //是否已载入default
        
     	if(parhtm!=null)
     	for(String thtid:parhtm.getKeys(false))
     	{//迭代子节点,创建HopTexts
     		//System.out.println(conhta.getString("hopTexts."+thtid+".text")+"emm");
     	    HPar2 ht;
     	    
     		if(thtid.equals("default"))
     	    {
     	    	ht = new HPar2(hta);
     	    	dhb = ht;
     	    	isdhb = true;
     	    }else if(isdhb)
     	    {//克隆default
     	        ht = (HPar2) dhb.clone();
     	        
     	    }else
     	    {
     	    	ht = new HPar2(hta);
     	    }
     	    	
     		String path = "HopModules." + thtid + ".";
     		//子节点路径
     		 
     		boolean papi = htf.getBoolean(path + "papi");
     		boolean endbyhop = htf.getBoolean(path + "endbyhop");
     		
     	    String cycle = htf.getString(path + "cycle");
     		String staytime = htf.getString(path + "staytime");
     		String ticktime = htf.getString(path + "ticktime");
     	     		
     		String text = htf.getString(path + "text");
     		String sub = htf.getString(path + "subtext");
     		
     		String hop = htf.getString(path + "hop");
    		String module = htf.getString(path + "module");

     		//读入
     		
     		if(papi)
     	    ht.setPapi(papi);
     		
     		if(endbyhop)
         	ht.setEndByHop(endbyhop);
     		
     		if(cycle!=null)
     		ht.setCycle(Integer.valueOf(cycle));
     		
     		if(staytime!=null)
         	ht.setStayTime(Integer.valueOf(staytime));

     		if(ticktime!=null)
         	ht.setTickTime(Integer.valueOf(ticktime));
     		
     		
     			
     		if(sub!=null)
        		if(sub.startsWith("hchat:"))
        		{
        			ht.setSubText(sub);
        		}else if(sub.startsWith("htitle:"))
        		{
        			ht.setSubText(sub);
        		}else if(sub.startsWith("hbar:"))
        		{
        			ht.setSubText(sub);
        		}
     	
     		if(text!=null)
        		ht.setText(text.replace("&", "§"));
        		
    		if(hop!=null)
    		{
     			
     			ht.setHoptypes(new ArrayList<String>());
     			ht.setHopargs(new ArrayList<String[]>());
     			ht.setFrameList(new ArrayList<String>());
     			//重新定义
     			String rows[] = hop.trim().replace("&", "§").split("\\n");
     			if(rows.length>0)
     			for(String row:rows)
     			if(!row.equals(""))
     			{
     				row = row.trim();
     				int b = row.indexOf("(");
     				int e = row.indexOf(")");

     				if(b==-1||e==-1)
     				continue;
     				
     				String ty = row.substring(0, b).toUpperCase();
     				String args[] = row.substring(b+1, e).split(",");
     				
     				ht.addTextHop(ty, args);
     				
     				
     			}
     			
     		}else if(text!=null)
    		{//重定义效果default里的"默认文本",重造
    			if(!ht.gethoptypes().isEmpty())
    			{
    				List<String> thtl = new ArrayList<String>(ht.gethoptypes());
        			List<String[]> thtal = new ArrayList<String[]>(ht.getHopargs());
        			ht.setHoptypes(new ArrayList<String>());
         			ht.setHopargs(new ArrayList<String[]>());	
        			ht.setFrameList(new ArrayList<String>());
    				
        			int in = 0;
        			for(String ty:thtl)
        			{
        				
        				ht.addTextHop(ty,thtal.get(in));
        				in++;
        			}
        			
    			}
    			
    		}
     		
    		if(module!=null)
    		{
    			ht.setModule(module);
    		}
    		
    		if(!thtid.equals("default"))
    		hta.addHopModule(thtid,ht);
    		
     	}
    		
    }
   
    /**一键从文件中载入对象*/
    public static void load(HManager hta,File f) throws Exception
    {
   
         YamlConfiguration htf = YamlConfiguration.loadConfiguration(f);
        
        //载入
       
         if(htf==null)
         System.out.print("未找到文件"+f.getPath());;
    	//.getConfigurationSection
    	//获取子节点map
    	//.getkeys(false)
    	//获取子节点keyset
         
        load_htm(hta,htf);
         
    	load_htx(hta,htf);
    	
    	load_htl(hta,htf);
    	
        load_htb(hta,htf);
    	
    	load_hto(hta,htf);
    	
    	if(HM.hololoaded)
    	load_hth(hta,htf);
    	
    }
    
    public static List<String> getList(String str)
    {
    	String[] a = str.trim().replace("&", "§").split("\\n");
    	
    	return Arrays.asList(a);
    }
    
	 
	
}
